package com.hwz.gulimall.ware.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwz.common.utils.PageUtils;
import com.hwz.common.utils.Query;

import com.hwz.gulimall.ware.dao.PurchaseDetailDao;
import com.hwz.gulimall.ware.entity.PurchaseDetailEntity;
import com.hwz.gulimall.ware.service.PurchaseDetailService;
import org.springframework.util.StringUtils;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<PurchaseDetailEntity> purchaseDetailEntityQueryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(params.get("key"))){
            purchaseDetailEntityQueryWrapper.and(w -> w.eq("purchase_id",params.get("key"))
                    .or().eq("sku_id",params.get("key")));
        }
        if (!StringUtils.isEmpty(params.get("status"))){
            purchaseDetailEntityQueryWrapper.eq("status",params.get("status"));
        }
        if (!StringUtils.isEmpty(params.get("wareId"))){
            purchaseDetailEntityQueryWrapper.eq("ware_id",params.get("wareId"));
        }

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                purchaseDetailEntityQueryWrapper
        );

        return new PageUtils(page);
    }

}